<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import Joomla view library
jimport('joomla.application.component.view');
 
/**
 * Orcers View
 */
class ShopViewOrderes extends JView
{
	/**
	 * Category view display method
	 * @return void
	 */
	function display($tpl = null) 
	{
	 // Get data from the model
		$this->state = $this->get('State');
		$this->items = $this->get('Items');
		$this->pagination = $this->get('Pagination');
		// Check for errors.
		
		if (count($errors = $this->get('Errors'))) 
		{
			JError::raiseError(500, implode('<br />', $errors));
			return false;
		}
 		$this->addToolBar();
		ShopHelper::addSubmenu('orderes');
		// Display the template
		parent::display($tpl);
	}
	/**
	 * Setting the toolbar
	 */
	protected function addToolBar() 
	{			
		JToolBarHelper::title('Danh sách quản cáo banner','order');
		$canDo = ShopHelper::getActions();
		if ($canDo->get('core.create')) 
		{
			JToolBarHelper::addNew('order.add');
		}
		if ($canDo->get('core.edit')) 
		{
			JToolBarHelper::editList('order.edit');
		}
		if ($canDo->get('core.delete')) 
		{
			JToolBarHelper::deleteList('', 'orderes.delete');
		}
		JToolBarHelper::divider();
		JToolBarHelper::back('Cpanel','index.php?option=com_shop');
		$document = JFactory::getDocument();
		$document->addStyleDeclaration('.icon-48-order {background-image: url(components/com_shop/images/order48x48.png);}');
	}
	protected function getOptions()
	{
		// Initialise variables.
		$options = array();
		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);
 		$query->select("t2.id as value,t2.title as text ,t2.level");
		$query->from("#__shop_address t1,#__shop_address t2");
		$query->where('t2.lft BETWEEN t1.lft AND t1.rgt');
		$query->group('t2.id,t2.lft,t2.rgt,t2.title');
		$query->order("t2.lft asc");

		// Get the options.
		$db->setQuery($query);
		$options = $db->loadObjectList();
		// Pad the option text with spaces using depth level as a multiplier.
		for ($i = 0, $n = count($options); $i < $n; $i++)
		{
			// Translate ROOT
			if ($options[$i]->level == 0) {
				$options[$i]->text = JText::_('JGLOBAL_ROOT_PARENT');
			}
			$options[$i]->text = str_repeat('- ',$options[$i]->level).$options[$i]->text;
		}

		// Merge any additional options in the XML definition.
		//$options = array_merge($thgetOptions(), $options);
		return $options;
	}
}